<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>数据 - AdminLTE2定制版</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- 页面meta /-->

    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}./plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/morris/morris.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/select2/select2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css" charset="UTF-8">
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">
    <div style="background-color: white">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                 数据管理
                 <small>数据列表</small>
             </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">数据管理</a></li>
                <li class="active">数据列表</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!-- .box-body -->
            <div class="box box-primary">
<%--                <div class="box-header with-border">--%>
<%--                    <h3 class="box-title">用户列表</h3>--%>
<%--                </div>--%>

                <div class="box-body">

                    <!-- 数据表格 -->
                    <div class="table-box">

                        <!--工具栏-->
                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default btn-info" data-toggle="modal" data-target="#addModal">
                                        <i class="fa fa-file-o"></i>新增
                                    </button>
                                    <%--                                    <button type="button" class="btn btn-default" title="新增"><i class="fa fa-file-o"></i> 新增</button>--%>
                                    <button type="button" onclick="delAll()"  class="btn btn-default btn-danger" title="批量删除"><i class="fa fa-trash-o"></i> 批量删除</button>
                                    <button type="button" class="btn btn-default" title="刷新" onclick="refreshUserList()"> <i class="fa fa-refresh"></i> 刷新</button>
                                </div>
                            </div>
                        </div>
                        <div class="box-tools pull-right">
                            <form   action="${pageContext.request.contextPath}/product/productList" method="post">
                                <div class="has-feedback form-inline">
                                    <input type="text" name="productName" value="${productName}" class="form-control input-sm" placeholder="产品名">

                                    <button type="submit" class="btn btn-default" title="搜索"><i class="fa fa-file-o"></i> 搜索</button>

                                </div>
                            </form>

                        </div>
                        <!--工具栏/-->

                        <!--数据列表-->
                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <th class="" style="padding-right:0px;">
                                    <input id="selall" type="checkbox"  class="icheckbox_square-blue">
                                </th>
                                <th class="sorting_asc">ID</th>
                                <th class="sorting_desc">产品编号</th>
                                <th class="sorting_desc">产品名称</th>
                                <th class="sorting_desc">出发城市</th>
                                <th class="sorting_desc">出发时间</th>
                                <th class="sorting_desc">产品价格</th>
                                <th class="sorting_desc">产品描述</th>
                                <th class="sorting_desc sorting_desc_disabled">状态 0 关闭 1 开启</th>

                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${productList}" var="item">
                                <tr>
                                    <td><input name="ids" type="checkbox" value="${item.id}"></td>
                                    <td>${item.id}</td>
                                    <td>${item.productNum}</td>
                                    <td>${item.productName}</td>
                                    <td>${item.cityName}</td>
                                    <td><fmt:formatDate value="${item.departureTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<%--                                    <td>${item.departureTime}</td>--%>
                                    <td>${item.productPrice}</td>
                                    <td>${item.productDesc}</td>
                                    <td>${item.productStatus}</td>
                                    <td class="text-center">
                                        <button type="button" class="btn btn-danger btn-xs" onclick="del(${item.id})">删除</button>
<%--                                        <button type="button" class="btn bg-olive btn-xs" data-toggle="model" onclick="detail(${item.id})" data-target="#detailModal">详情</button>--%>
                                        <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#detailModal" onclick="detail(${item.id})">详情</button>
                                        <button type="button" class="btn btn-info btn-xs" data-toggle="modal" onclick="getUserById(${item.id})" data-target="#editModal">编辑</button>
                                    </td>
                                </tr>

                            </c:forEach>
                            </tbody>


                        </table>
                    </div>
                </div>
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共${pageInfo.pages} 页，共${pageInfo.total} 条数据。 每页
                            <select class="form-control" onchange="selectPages()" id="selectPages">
                                <option>5</option>
                                <option >10</option>
                                <option>15</option>
                                <option>20</option>
                                <option>30</option>
                            </select> 条
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?pageNum=1&pageSize=${pageInfo.pageSize}&productName=${productName}" aria-label="Previous">首页</a>
                            </li>
                            <li><a href="${pageContext.request.contextPath}/product/productList?pageNum=${pageInfo.prePage==0?1:pageInfo.prePage}&pageSize=${pageInfo.pageSize}&productName=${productName}">上一页</a></li>
                            <c:forEach begin="1" end="${pageInfo.pages}" var="pageNo">
                                <li><a href="${pageContext.request.contextPath}/product/productList?pageNum=${pageNo}&pageSize=${pageInfo.pageSize}&productName=${productName}">${pageNo}</a></li>
                            </c:forEach>
                            <li><a href="${pageContext.request.contextPath}/product/productList?pageNum=${pageInfo.nextPage==0?pageInfo.pages:pageInfo.nextPage}&pageSize=${pageInfo.pageSize}&productName=${productName}">下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?pageNum=${pageInfo.pages}&pageSize=${pageInfo.pageSize}&productName=${productName}" aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>

                </div>
                <!-- /.box-footer-->



            </div>

        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- @@close -->
    <!-- 内容区域 /-->
    <!-- Button trigger modal -->

    <!-- 新增窗口Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="addModalLabel">新增产品</h4>
                </div>
                <div class="modal-body">
                    <form class="form-inline" id="addForm">
                        <div class="row data-type">
                            <div class="col-md-2 title">产品编号</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="产品编号" name="productNum" id="productNum">
                            </div>
                            <div class="col-md-2 title">产品名称</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="产品名称" name="productName" id="productName">
                            </div>
                            <div class="col-md-2 title">出发城市</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="出发城市" name="cityName" id="cityName">
                            </div>
                            <div class="col-md-2 title">出发时间</div>
                            <div class="col-md-4 data">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" placeholder="出发时间" id="departureTime" name="departureTime">
                                </div>
                            </div>
                            <div class="col-md-2 title">产品价格</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="产品价格" name="productPrice" id="productPrice">
                            </div>
                            <div class="col-md-2 title">产品描述</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="产品描述" name="productDesc" id="productDesc">
                            </div>
                            <div class="col-md-2 title">状态 0 关闭 1 开启</div>
                            <div class="col-md-4 data text">
                                <input type="text" class="form-control" placeholder="状态 0 关闭 1 开启" name="productStatus" id="productStatus">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="save()" class="btn btn-primary" >保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 编辑窗口Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="editModalLabel">编辑产品</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" id="editForm">
                    <div class="row data-type">
                        <div class="col-md-2 title">ID</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="ID" name="id" id="uid">
                        </div>
                        <div class="col-md-2 title">产品编号</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品编号" name="productNum" id="uproductNum">
                        </div>
                        <div class="col-md-2 title">产品名称</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品名称" name="productName" id="uproductName">
                        </div>
                        <div class="col-md-2 title">出发城市</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="出发城市" name="cityName" id="ucityName">
                        </div>
                        <div class="col-md-2 title">出发时间</div>
                        <div class="col-md-4 data">
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-right" placeholder="出发时间" id="udepartureTime" name="departureTime" value="<fmt:formatDate value="${item.departureTime}" pattern="yyyy-MM-dd HH:mm:ss"/>">
                            </div>
                        </div>
                        <div class="col-md-2 title">产品价格</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品价格" name="productPrice" id="uproductPrice">
                        </div>
                        <div class="col-md-2 title">产品描述</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品描述" name="productDesc" id="uproductDesc">
                        </div>
                        <div class="col-md-2 title">状态 0 关闭 1 开启</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="状态 0 关闭 1 开启" name="productStatus" id="uproductStatus">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="edit()" class="btn btn-primary" >保存</button>
            </div>
        </div>
    </div>
</div>


<!-- 详情窗口Modal -->
<div class="modal fade" id="detailModal" tabindex="-1" role="dialog" aria-labelledby="detailModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="detailModalLabel">产品详情</h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" id="detailForm">
                    <div class="row data-type">
                        <div class="col-md-2 title">ID</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="id" name="id" id="did" disabled>
                        </div>
                        <div class="col-md-2 title">产品编号</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品编号" name="productNum" id="dproductNum" disabled>
                        </div>
                        <div class="col-md-2 title">产品名称</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品名称" name="productName" id="dproductName" disabled>
                        </div>
                        <div class="col-md-2 title">出发城市</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="出发城市" name="cityName" id="dcityName" disabled>
                        </div>
                        <div class="col-md-2 title">出发时间</div>
                        <div class="col-md-4 data">
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-right" id="ddepartureTime" name="departureTime" disabled>
                            </div>
                        </div>
                        <div class="col-md-2 title">产品价格</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品价格" name="productPrice" id="dproductPrice" disabled>
                        </div>
                        <div class="col-md-2 title">产品描述</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="产品描述" name="productDesc" id="dproductDesc" disabled>
                        </div>
                        <div class="col-md-2 title">状态 0 关闭 1 开启</div>
                        <div class="col-md-4 data text">
                            <input type="text" class="form-control" placeholder="状态 0 关闭 1 开启" name="productStatus" id="dproductStatus" disabled>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="det()" class="btn btn-primary" >保存</button>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/raphael/raphael-min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/morris/morris.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="${pageContext.request.contextPath}/plugins/knob/jquery.knob.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/moment.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datepicker/bootstrap-datepicker.js"></script>
<%--<script src="${pageContext.request.contextPath}/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>--%>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/treeTable/jquery.treetable.js"></script>
<script src="${pageContext.request.contextPath}/plugins/select2/select2.full.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="${pageContext.request.contextPath}/plugins/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="${pageContext.request.contextPath}/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/chartjs/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<%--<script src="${pageContext.request.contextPath}/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>--%>
<script>
    $(document).ready(function() {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function() {

        // 激活导航位置
        setSidebarActive("admin-datalist");

        // 列表按钮
        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function() {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });
    });

    /**
     * 刷新
     */
    function refreshUserList() {
        location.href = "${pageContext.request.contextPath}/product/productList";
    }
    /**
     * 保存
     */
    function save() {
        console.log("保存数据！")

        var data = $("#addForm input").serialize();
        console.log(data);
        var url = "${pageContext.request.contextPath}/product/addProduct";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success){
                window.location.href="${pageContext.request.contextPath}/product/productList";
            }
        })
    }

    function edit() {
        console.log("保存数据！")
        var data = $("#editForm input").serialize();
        console.log(data);
        var url = "${pageContext.request.contextPath}/product/editProduct";
        $.post(url,data,function (response) {
            alert(response.msg);
            if (response.success){
                window.location.href="${pageContext.request.contextPath}/product/productList";
            }
        })
    }


    function det() {
        console.log("保存数据！")
        var data = $("#detailForm input").serialize();
        console.log(data);
        var url = "${pageContext.request.contextPath}/product/detailProduct";
        $.post(url,data,function (response) {
            alert(response.msg);
            if (response.success){
                window.location.href="${pageContext.request.contextPath}/product/productList";
            }
        })
    }

    /**
     * 删除
     */
    function del(id) {
        console.log("删除数据！")
        console.log(id);
        var data = {id:id};
        var url = "${pageContext.request.contextPath}/product/delProduct";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success) {
                window.location.href = "${pageContext.request.contextPath}/product/productList";
            }
        })
    }
    /**
     * 批量删除
     */
    function delAll() {
        console.log("批量删除数据！")
        var $dataList = $("#dataList input:checked");

        console.log($dataList)
        var datas = new Array();
        $dataList.each(function () {
            //  $(this);
            console.log($(this).val())
            datas.push($(this).val());
        })
        console.log(datas)
        var ids = datas.join(",");
        console.log(ids)
        if(ids==''){
            alert("请选择数据！")
            return;
        }
        var data={ids:ids};

        var url = "${pageContext.request.contextPath}/product/delAllProduct";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success){
                window.location.href="${pageContext.request.contextPath}/product/productList";
            }
        })
    }

    /**
     * 根据id查询用户
     */
    function getUserById(id){
        console.log("查询用户id！")
        console.log(id);
        var data = {id:id};
        var url = "${pageContext.request.contextPath}/product/getProductById";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success) {
                $("#uproductNum").val(response.data.productNum);
                $("#uproductName").val(response.data.productName);
                $("#ucityName").val(response.data.cityName);
                $("#udepartureTime").val(response.data.departureTime);
                $("#uproductPrice").val(response.data.productPrice);
                $("#uproductDesc").val(response.data.productDesc);
                $("#uproductStatus").val(response.data.productStatus);
                $("#uid").val(response.data.id);
            }
        })
    }

    /**
     * 编辑
     */
    function update(id) {
        console.log("编辑数据！")
        console.log(id);
        var data = {id:id};
        var url = "${pageContext.request.contextPath}/product/editProduct";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success) {
                window.location.href = "${pageContext.request.contextPath}/product/productList";
            }
        })
    }

    /**
     * 详情
     */
    function detail(id) {
        console.log("查询用户id！")
        console.log(id);
        var data = {id:id};
        var url = "${pageContext.request.contextPath}/product/detailProduct";
        $.post(url,data,function (response) {
            console.log("收到数据！");
            console.log(response);
            alert(response.msg);
            if (response.success) {
                $("#dproductNum").val(response.data.productNum);
                $("#dproductName").val(response.data.productName);
                $("#dcityName").val(response.data.cityName);
                $("#ddepartureTime").val(response.data.departureTime);
                $("#dproductPrice").val(response.data.productPrice);
                $("#dproductDesc").val(response.data.productDesc);
                $("#dproductStatus").val(response.data.productStatus);
                $("#did").val(response.data.id);
            }
        })
    }

    function processDepartureTime() {
        var departureTimeStamp = response.data.departureTime;
        var departureTime = new Date(departureTimeStamp);
        var formattedDepartureTime = departureTime.getFullYear() + '-' +
            (departureTime.getMonth() + 1).toString().padStart(2, '0') + '-' +
            departureTime.getDate().toString().padStart(2, '0') +'' +
            departureTime.getHours().toString().padStart(2, '0') + ':' +
            departureTime.getMinutes().toString().padStart(2, '0');
        $("#ddepartureTime").val(formattedDepartureTime);
    }

    function selectPages() {
        // 获取下拉列表选中的每页条数
        var pageSize = $("#selectPages").val();
        // 获取当前页数，如果URL中没有pageNum参数则默认为1
        var currentPage = getUrlParam('pageNum') || 1;
        // 构造正确的URL，带上当前页数、选中的每页条数以及其他已有参数（这里假设username是从后端传来的已有参数，可按需修改）
        var url = "${pageContext.request.contextPath}/product/productList?pageNum=" + currentPage + "&pageSize=" + pageSize + "&productName=${productName}";
        // 使用window.location.href进行页面跳转，跳转到新构造的URL对应的页面
        window.location.href = url;
    }

    // 给下拉列表绑定change事件，当选项改变时触发selectPages函数
    $("#selectPages").change(selectPages);

    $('#departureTime').datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true,
        todayBtn: true,
        //language: 'en-US'
        language: 'zh-CN'
    });

    $('#udepartureTime').datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true,
        todayBtn: true,
        //language: 'en-US'
        language: 'zh-CN'
    });
</script>
</body>
<script>
    // 以下自执行函数用于为日期时间选择器插件配置中文语言环境
    ;(function($) {
        // 为$.fn.datetimepicker.dates['zh-CN']添加中文语言相关配置
        $.fn.datetimepicker.dates['zh-CN'] = {
            days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
            daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
            daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
            months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            today: "今天",
            suffix: [],
            meridiem: ["上午", "下午"]
        };
    }(jQuery));
</script>
</html>
